package com.hnevc.xiaoming.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.hnevc.xiaoming.R;
import com.hnevc.xiaoming.httpbean.NewsBean;

import java.util.List;

public class NewsAdapter extends BaseAdapter {

    private List<NewsBean.ResultBean.DataBean> list;
    private Context context;
    private ViewHolder viewHolder;
    private NewsBean.ResultBean.DataBean data;

    public NewsAdapter(List<NewsBean.ResultBean.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = View.inflate(context, R.layout.news_itme_layout, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }
            convertView.getTag();
        data = list.get(position);
        viewHolder.news_itme_img.setImageResource(R.mipmap.c);
//        viewHolder.news_itme_img.loadUrl(data.getThumbnail_pic_s02());
        viewHolder.news_itme_tite.setText(data.getTitle());
        viewHolder.news_itme_name.setText(data.getAuthor_name());
        viewHolder.news_itme_date.setText(data.getDate());
        Glide.with(context)
                .load(data.getThumbnail_pic_s())
                .into(viewHolder.news_itme_img);

        return convertView;
    }

    public static
    class ViewHolder {
        public View rootView;
        public ImageView news_itme_img;
//        public WebView news_itme_img;
        public TextView news_itme_tite;
        public TextView news_itme_name;
        public TextView news_itme_date;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.news_itme_img =  rootView.findViewById(R.id.news_itme_img);
            this.news_itme_tite = (TextView) rootView.findViewById(R.id.news_itme_tite);
            this.news_itme_name = (TextView) rootView.findViewById(R.id.news_itme_name);
            this.news_itme_date = (TextView) rootView.findViewById(R.id.news_itme_date);
        }

    }
}
